<template>
	<view>
		<view class="status_bar">
		    <!-- 这里是状态栏 -->
		</view>
		<uni-nav-bar fixed >
			<view style="width: 220px;" >
				<uni-title type="h2" title="积分汇总" align="center"></uni-title>
			</view>
			<view  slot="left">
				<uni-icons type="left" size="25px" @click="goback()"></uni-icons>
			</view>
			<view  slot="right">
			</view>
		</uni-nav-bar>
		<view v-if="getfinish" style="width: 100%;display: flex;flex-direction: column;margin-top: 20px;">
			<view v-for="(a,index) in summary_list" class="shadow" style="width: 90%;align-self: center;display: flex;flex-direction: row;justify-content:space-between;margin-bottom: 15px;">
				<view style="width: 50%;"><image mode='aspectFill' :src="httpurl+a.activity.a_cover" style="height: 130px;width: 160px;" @click="activity_detail(a.activity.a_id)"></image></view>
				<view style="width: 50%;">
					<view style="margin-top: 10px; margin-left: 10px;font-weight: 500;">{{a.activity.a_name}}</view>
					<view style="margin-left: 10px;font-size: 13px;color: #f8af41;" >{{gettimerange(a.activity.a_start_time,a.activity.a_end_time)}}</view>
					<view style="margin-left: 10px;font-size: 13px;color: #808080;">{{a.activity.type_name}}</view>
					<view v-if="a.isSign=='0'" style="margin-left: 10px;font-size: 20px;font-weight: 300;margin-top: 15px;">进行中</view>
					<view v-if="a.isSign=='1'" style="margin-left: 10px;font-size: 20px;font-weight: 300;margin-top: 15px;">{{'+'+a.activity.a_score}}</view>
				</view>
			</view>
			<!-- 汇总 -->
			<view  style="width: 90%;align-self: center;margin-top: 10px;">
				<uni-title  type="h1" align="right" :title="'共报名：'+summary_num+'次'"></uni-title>
				<uni-title type="h1" align="right" :title="'总共收到积分：'+summary_score+'分'"></uni-title>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				httpurl: getApp().globalData.weburl, //app.vue中定义的全局变量，后端ip地址
				myActivity:[],
				getfinish:false,
				summary_list:[],
				summary_num:'',
				summary_score:'',
			}
		},
		computed:{
			gettimerange() {
			    return (time1,time2) => {
					return time1.substr(5, 5)+"至"+time2.substr(5, 5);
			    }
			}
		},
		onLoad: function (option) {
			this.getMyActivity();
		},
		onPullDownRefresh() {
			console.log('下拉刷新');
			this.getMyActivity();
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 500);
		},
		methods: {
			goback(){
				console.log("返回")
				uni.navigateBack({
				    delta: 1,//新注释
				});
			},
			activity_detail(id){
				console.log("点击");
				uni.navigateTo({
					url:"../activity_detail/activity_detail?a_id="+id
				});
			},
			getMyActivity(){
				var that=this;
				uni.request({
				    url: that.httpurl+'getMyActivity/', //服务器地址+接口名
				    data: {
						s_id:getApp().globalData.userid,
				    },
					method: 'POST',
				    header: { 
						'X-Requested-With': 'XMLHttpRequest',
						"Accept": "application/json",
						"Content-Type": "application/json; charset=UTF-8"
					},
					dataType: 'json',
				    success: (res) => {
						console.log("request success");
				        console.log(res.data);
						that.summary_list = res.data.summary_list;
						that.summary_num = res.data.num;
						that.summary_score = res.data.score;
						that.getfinish=true;
				    },
					fail: (res) => {
						console.log("request fail");
				    },
				});
			}
			
		}
	}
</script>

<style>
	.status_bar {
	    height: var(--status-bar-height);
	    width: 100%;
		background-color:#ffffff;
	}
	.shadow{
		box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, .3);
	}
</style>
